#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define ll long long
#define int ll
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define popcnt __builtin_popcount
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=4e3+10,maxm=1e6+10,mod=998244353,inf=INT_MAX;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(x%=mod;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

int n,q,a[maxn][maxn];

signed main(){
	freopen("fire.in","r",stdin),freopen("fire.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>q;
	rep(o,1,q){
		int opt;
		cin>>opt;
		if(opt==1){
			int dir,i,opt,x;
			cin>>dir>>i>>opt>>x;
			if(dir==0){
				rep(j,1,n) if(opt==1) a[i][j]&=x;
				else if(opt==2) a[i][j]|=x;
				else if(opt==3) a[i][j]^=x;
				else (a[i][j]+=x)%=999999999;
			}
			else{
				rep(j,1,n) if(opt==1) a[j][i]&=x;
				else if(opt==2) a[j][i]|=x;
				else if(opt==3) a[j][i]^=x;
				else (a[j][i]+=x)%=999999999;
			}
		}
		else{
			int p,q,sum=0;
			cin>>p>>q;
			rep(i,1,p) rep(j,1,q) sum+=a[i][j];
			cout<<sum<<'\n';
		}
	}
	return 0;
}
